package com.system.enterprisemanagementsystem.mapper;

import com.system.enterprisemanagementsystem.pojo.Clazz;
import com.system.enterprisemanagementsystem.pojo.Student;
import com.system.enterprisemanagementsystem.pojo.StudentQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {

    List<Student> selectByCondition(StudentQueryParam studentQueryParam);

    @Select("select * from student where id = #{id}")
    Student getStudentById(int id);


    /**
     * 添加学生
     * @param student
     */
    @Insert("""
        INSERT INTO student
        (name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id, violation_count, violation_score, create_time, update_time)
        VALUES
        (#{name}, #{no}, #{gender}, #{phone}, #{idCard}, #{isCollege}, #{address}, #{degree}, #{graduationDate}, #{clazzId}, 0, 0, NOW(), NOW())
    """)
    void addStudent(Student student);

    /**
     * 更新单个学生
     * @param student
     */
    void updateStudent(Student student);

    /**
     * 批量删除学员
     * @param ids 学员ID列表
     * @return 影响的行数
     */
    int deleteByIds(@Param("ids") List<Integer> ids);

    /**
     * 更新学员违纪信息
     */
    int updateStudentViolation(Student student);

    /**
     * 按学历统计学生人数
     * @return 学历统计列表
     */
    @MapKey("degree")
    List<Map<String, Object>> countStudentsByDegree();
}
